Looks like UTF8Encoding.Default would return a default instance of the UTF8Encoding, right?
Well, it doesn’t – it returns the operating system’s default ANSI encoding.
The same with ASCIIEncoding.Default, UnicodeEncoding.Default, UTF32Encoding.Default and UTF7Encoding.Default!
Why? Because they all derive from System.Text.Encoding where Default is definded:
/// <summary> /// Gets an encoding for the operating /// system's current ANSI code page. /// </summary> public static System.Text.Encoding Default { get; }
So instead use Encoding.ASCII, Encoding.UTF8, Encoding.UTF7, Encoding.UTF32 and Encoding.Unicode to refer explicitly to an encoding.
thx
You can also use UTF8Encoding.UTF8 – yes, it’s the same, derived for the same reason as the Default property.
Have even seen people using UTF8encoding.ASCII 🙂
UTF8encoding.ASCII, just the other day now you mention it!
Made me almost cry!
Spent a few hours before finding that out (UTF8Encoding.Default != Encoding.UTF8).
Makes me wanna cry now 😦